function login() {
    event.preventDefault()
    userId = $("input#inputEmail").val()
    user_pwd = $("input#inputPassword").val()

    $.get(
        "http://localhost:8080/login",
        { "userId": userId, "user_pwd": user_pwd },
        function (result) {
            if (result.code == 0) {
                alert("登录失败")
            } else {
                $.cookie('user_id', userId)
                $.cookie('user_pwd', user_pwd)
                $.cookie('user_name', result.username)
                window.location.replace("index.html")
            }
        }
    )
}

function veri() {
    if($.cookie('user_name')) {
        window.location.replace("index.html")
    }
}

function register() {
    event.preventDefault()
    userName = $("input#inputEmail").val()
    user_pwd = $("input#inputPassword").val()

    $.get(
        "http://localhost:8080/register",
        { "userName": userName, "user_pwd": user_pwd },
        function (result) {
            if (result.code == 0) {
                alert("注册失败，用户名已存在")
            } else {
                alert("注册成功！你的 ID 是 " + result.user_id)
                window.location.replace("login.html")
            }
        }
    )
}